package com.lizhi.menu.controller;

import com.lizhi.menu.common.response.Result;
import com.lizhi.menu.domain.MenuInfo;
import com.lizhi.menu.service.IMenuInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜谱Controller
 *
 * @author lizhi
 * @date 2023-05-18
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/info")
@Api(tags = "菜谱管理")
public class MenuInfoController {

    private final IMenuInfoService menuInfoService;

    /**
     * 查询菜谱列表
     */
    @GetMapping("/list")
    @ApiOperation("查询菜谱列表")
    public Result<List<MenuInfo>> list(MenuInfo menuInfo) {
        List<MenuInfo> list = menuInfoService.selectMenuInfoList(menuInfo);
        return Result.ok(list);
    }

    /**
     * 获取菜谱详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation("获取菜谱详细信息")
    public Result<MenuInfo> getInfo(@PathVariable("id") Long id) {
        return Result.ok(menuInfoService.selectMenuInfoById(id));
    }

    /**
     * 新增菜谱
     */
    @PostMapping
    @ApiOperation("新增菜谱")
    public Result<Void> add(@RequestBody MenuInfo menuInfo) {
        menuInfoService.insertMenuInfo(menuInfo);
        return Result.ok();
    }

    /**
     * 修改菜谱
     */
    @PutMapping
    @ApiOperation("修改菜谱")
    public Result<Void> edit(@RequestBody MenuInfo menuInfo) {
        menuInfoService.updateMenuInfo(menuInfo);
        return Result.ok();
    }

    /**
     * 删除菜谱
     */
    @DeleteMapping("/{ids}")
    @ApiOperation("删除菜谱")
    public Result<Void> remove(@PathVariable Long[] ids) {
        menuInfoService.deleteMenuInfoByIds(ids);
        return Result.ok();
    }
}
